angular.module('tab-orderDetail', [])
.controller 'OrderDetailCtrl', ($location,Toast, $localStorage, $ionicLoading, $scope, $state, $http,$stateParams, $window, $ionicHistory, $ionicPopup, orderService) ->
 $scope.orderId=$stateParams.id;
 console.log($scope.orderId)
 #获取订单数据
 loadData = ->
  $http.get('/crewOrder/'+$scope.orderId)
   .success (resp) ->
    $scope.order=resp.message
    console.log($scope.order)
    if $scope.order.shift==1
     $scope.banci="白班"
    else if $scope.order.shift==0
     $scope.banci="全天"
    else
     $scope.banci="夜班"
    $scope.dayList=$scope.order.orderTracks
   .error (resp, status) ->
    Toast.showBusinessError(resp.message)
 loadData()

 #返回
 $scope.back= ->
  $state.go('tab.order-list')

 #确认服务
 $scope.toSure = (id)->
  myPopup = $ionicPopup.confirm({
   title: '是否确认服务完成'
   template: ''
   okText: '确认'
   cancelText: '我再想想'
   cssClass:'my-custom-popup'
  })
  myPopup.then (res) ->
   if res
    $http.put('/orderTrack/'+id, {id: id})
     .success (resp) ->
      Toast.showMsg("确认服务完成")
      $window.location.reload()
     .error (resp, status) ->
      Toast.showBusinessError(resp.message)
   else
